"use strict";
exports.__esModule = true;
exports.equals = exports.nullize = exports.getProperty = exports.random = void 0;
function random(min, max) {
    min = Math.ceil(min);
    max = Math.floor(max);
    //The maximum is exclusive and the minimum is inclusive
    return Math.floor(Math.random() * (max - min)) + min;
}
exports.random = random;
function getProperty(o, name) {
    return o[name]; // o[name] is of type T[K]
}
exports.getProperty = getProperty;
function nullize(o) {
    for (var key in o) {
        // todo: o[key] as object 不做强转的类型报错 后续再思考怎么处理
        if (typeof o[key] === "object" && o[key] instanceof Array) {
            // todo: 类型不强转就报错的问题后续再处理
            o[key] = [];
            continue;
        }
        if (typeof o[key] === "object") {
            nullize(o[key]);
            continue;
        }
        // todo: 类型不强转就报错的问题后续再处理
        o[key] = null;
    }
}
exports.nullize = nullize;
function equals(o1, o2) {
    if (typeof o1 !== typeof o2) {
        return false;
    }
    if (typeof o1 == "string" || typeof o1 == "number" || o1 === null || typeof o1 == "boolean") {
        return o1 === o2;
    }
    if (typeof o1 == "object" && !(o1 instanceof Array)) {
        for (var key in o1) {
            if (o2[key] === undefined) {
                return false;
            }
            if (!equals(o1[key], o2[key])) {
                return false;
            }
        }
        return true;
    }
    // array
    if (o1 instanceof Array && o2 instanceof Array) {
        if (o1.length != o2.length) {
            return false;
        }
        for (var i = 0; i < o1.length; ++i) {
            if (!equals(o1[i], o2[i])) {
                return false;
            }
        }
        return true;
    }
    return false;
}
exports.equals = equals;
